package com.sanyue.codingsettlement.mqstudy.rabbitmq.workqueues;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;

/**
 * @author: Guan
 **/
public class NewTask {
    private final static String QUEUE_NAME = "work_queue";

    public static void main(String[] argv) throws Exception {
        //1.创建连接
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {
            //2.声明队列
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            for (int i = 1;i <= 4;i++){
                String message = "这是第" + i  + "条数据";
                for(int j = 1;j <= i;j++){
                    message += ".";
                }
                //4.发送消息
                channel.basicPublish("", "work_queue", null, message.getBytes());
                System.out.println(" [x] Sent '" + message + "'");
            }


        }

    }
}
